<?php
    require('./Utils.php');

    $data_count = 10;
    $page = $_GET['page'] - 1;

    if($page < 0)
        $page = 0;

    $sql_page = $page * $data_count;

    $sql = "SELECT t.type type, k.kind kind, name, intro,p.id, price, p.image, stock
            FROM  pet p LEFT JOIN pet_type t
            ON p.type_id = t.id LEFT JOIN pet_kind k
            ON p.kind_id = k.id LIMIT ?,?";

    $conn = getConnection();
    $pet_list = query_list($conn,$sql, $sql_page, $data_count);
    $data = array();

    $data['pet_list'] = $pet_list;

    $sql = "SELECT count(*) count FROM  pet";
    $res = query($conn, $sql);

    $count_total = $res['count'];

    $total_page = $count_total % $data_count > 0 ? $count_total / $data_count + 1 : $count_total / $data_count;
    $now_page = $page + 1;

    $data['totalPage'] = (int)$total_page;
    $data['nowPage'] = $now_page;

    getJson(200, '获取成功', $data);
?>